package com.st.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.st.entity.*;
import com.st.mapper.ICityMapper;
import com.st.mapper.IOrderMapper;
import com.st.service.ICityService;
import com.st.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class OrderServiceImpl extends ServiceImpl<IOrderMapper, Order> implements IOrderService {
    @Autowired
    private IOrderMapper iOrderMapper;


    @Override
    public PageResult<Order> findOrders(PageDTO<Order> pageDTO) {
        if (pageDTO == null) {
            return new PageResult<Order>(false, "查询失败", null, null, null);
        }
        IPage<Order> iPage = new Page<>(pageDTO.getPage(), pageDTO.getLimit());
        Order data = pageDTO.getData();
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>(pageDTO.getData());
        if (!StringUtils.isEmpty(data.getAttractionsId())) {
            queryWrapper.eq("attractions_id", data.getAttractionsId());
        }
        if (!StringUtils.isEmpty(data.getOrderStatu())) {
            queryWrapper.eq("order_statu", data.getOrderStatu());
        }
        IPage<Order> pageInfo = iOrderMapper.findOrder(iPage, pageDTO.getData());
        PageResult pageResult = new PageResult<>();
        pageResult.setSuccess(true);
        pageResult.setData(pageInfo.getRecords());
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setMsg("查询成功");
        return pageResult;
    }

    @Override
    public Result delOne(Order order) {
//        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("id",order.getId());
        int delete = iOrderMapper.deleteById(order.getId());
        return delete==1?new Result(true,"删除成功"):new Result(false,"删除失败");
    }
}
